﻿using AiMoWindows.GHAiMo;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Parameters;
using System.Linq;

namespace AiMoInGH.Connector
{
    class ParamAnalyzer
    {
        public static bool IsDifferentType(ParamInfo info, IGH_Param param)
        {
            string paramTypeName = param.GetType().Name;

            switch (paramTypeName)
            {
                case "Param_GenericObject":
                    return info.ParamType != GH_ParamType.Param_GenericObject;
                case "Param_Arc":
                    return info.ParamType != GH_ParamType.Param_Arc;
                case "Param_Boolean":
                    return info.ParamType != GH_ParamType.Param_Boolean;
                case "Param_Box":
                    return info.ParamType != GH_ParamType.Param_Box;
                case "Param_Brep":
                    return info.ParamType != GH_ParamType.Param_Brep;
                case "Param_Circle":
                    return info.ParamType != GH_ParamType.Param_Circle;
                case "Param_Colour":
                    return info.ParamType != GH_ParamType.Param_Colour;
                case "Param_Complex":
                    return info.ParamType != GH_ParamType.Param_Complex;
                case "Param_Culture":
                    return info.ParamType != GH_ParamType.Param_Culture;
                case "Param_Curve":
                    return info.ParamType != GH_ParamType.Param_Curve;
                case "Param_Field":
                    return info.ParamType != GH_ParamType.Param_Field;
                case "Param_Geometry":
                    return info.ParamType != GH_ParamType.Param_Geometry;
                case "Param_Group":
                    return info.ParamType != GH_ParamType.Param_Group;
                case "Param_Integer":
                    return info.ParamType != GH_ParamType.Param_Integer;
                case "Param_Interval":
                    return info.ParamType != GH_ParamType.Param_Interval;
                case "Param_Interval2D":
                    return info.ParamType != GH_ParamType.Param_Interval2D;
                case "Param_Line":
                    return info.ParamType != GH_ParamType.Param_Line;
                case "Param_Matrix":
                    return info.ParamType != GH_ParamType.Param_Matrix;
                case "Param_Mesh":
                    return info.ParamType != GH_ParamType.Param_Mesh;
                case "Param_MeshFace":
                    return info.ParamType != GH_ParamType.Param_MeshFace;
                case "Param_Number":
                    return info.ParamType != GH_ParamType.Param_Number;
                case "Param_Plane":
                    return info.ParamType != GH_ParamType.Param_Plane;
                case "Param_Point":
                    return info.ParamType != GH_ParamType.Param_Point;
                case "Param_Rectangle":
                    return info.ParamType != GH_ParamType.Param_Rectangle;
                case "Param_ScriptVariable":
                    return info.ParamType != GH_ParamType.Param_ScriptVariable;
                case "Param_String":
                    return info.ParamType != GH_ParamType.Param_String;
                case "Param_StructurePath":
                    return info.ParamType != GH_ParamType.Param_StructurePath;
                case "Param_Surface":
                    return info.ParamType != GH_ParamType.Param_Surface;
                case "Param_Time":
                    return info.ParamType != GH_ParamType.Param_Time;
                case "Param_Transform":
                    return info.ParamType != GH_ParamType.Param_Transform;
                case "Param_Vector":
                    return info.ParamType != GH_ParamType.Param_Vector;
                default:
                    return true; // If the type is not recognized, consider it different
            }
        }
        public static ParamInfo[] GetInputInfo(GH_ParamSyntaxNodeInfo[] infos)
        {
            return infos
                        .Where(x => x.MethodName.StartsWith("Get"))
                        .OrderBy(x => x.Index)
                        .Select(x => new ParamInfo(x.ParamName, GetAccess(x), GetParamType(x)))
                        .ToArray();
        }
        public static ParamInfo[] GetOutputInfo(GH_ParamSyntaxNodeInfo[] infos)
        {
            return infos
                        .Where(x => x.MethodName.StartsWith("Set"))
                        .OrderBy(x => x.Index)
                        .Select(x => new ParamInfo(x.ParamName, GetAccess(x), GetParamType(x)))
                        .ToArray();
        }

        static GH_ParamType GetParamType(GH_ParamSyntaxNodeInfo info)
        {
#warning WIP AI生成这段代码，不确定每个都能用
            string typeName = info.TypeName;
            switch (typeName)
            {
                default:
                    return GH_ParamType.Param_GenericObject;
                case "Arc": //RhinoCommon
                case "GH_Arc": //GH_Goo
                    return GH_ParamType.Param_Arc;
                case "bool": // system
                case "GH_Boolean": //GH_Goo
                    return GH_ParamType.Param_Boolean;
                case "Box": //RhinoCommon
                case "GH_Box"://GH_Goo
                    return GH_ParamType.Param_Box;
                case "Brep": //RhinoCommon
                case "GH_Brep": //GH_Goo
                    return GH_ParamType.Param_Brep;
                case "Circle": //RhinoCommon
                case "GH_Circle": //GH_Goo
                    return GH_ParamType.Param_Circle;
                case "Color": // system
                case "GH_Colour": //GH_Goo
                    return GH_ParamType.Param_Colour;
                case "Complex": //RhinoCommon
                case "GH_Complex": //GH_Goo
                    return GH_ParamType.Param_Complex;
                case "CultureInfo": // system
                case "GH_Culture": //GH_Goo
                    return GH_ParamType.Param_Culture;
                case "Curve": //RhinoCommon
                case "Polyline":
                case "GH_Curve": //GH_Goo
                    return GH_ParamType.Param_Curve;
                case "Field": //RhinoCommon
                case "GH_Field": //GH_Goo
                    return GH_ParamType.Param_Field;
                case "GeometryBase": //RhinoCommon
                case "GH_Geometry": //GH_Goo
                    return GH_ParamType.Param_Geometry;
                case "Group": //RhinoCommon
                case "GH_Group": //GH_Goo
                    return GH_ParamType.Param_Group;
                case "int": // system
                case "GH_Integer": //GH_Goo
                    return GH_ParamType.Param_Integer;
                case "Interval": //RhinoCommon
                case "GH_Interval": //GH_Goo
                    return GH_ParamType.Param_Interval;
                case "Interval2d": //RhinoCommon
                case "GH_Interval2D": //GH_Goo
                    return GH_ParamType.Param_Interval2D;
                case "Line": //RhinoCommon
                case "GH_Line": //GH_Goo
                    return GH_ParamType.Param_Line;
                case "Matrix": //RhinoCommon
                case "GH_Matrix": //GH_Goo
                    return GH_ParamType.Param_Matrix;
                case "Mesh": //RhinoCommon
                case "GH_Mesh": //GH_Goo
                    return GH_ParamType.Param_Mesh;
                case "MeshFace": //RhinoCommon
                case "GH_MeshFace": //GH_Goo
                    return GH_ParamType.Param_MeshFace;
                case "double": // system
                case "GH_Number": //GH_Goo
                    return GH_ParamType.Param_Number;
                case "Plane": //RhinoCommon
                case "GH_Plane": //GH_Goo
                    return GH_ParamType.Param_Plane;
                case "Point3d": //RhinoCommon
                case "GH_Point": //GH_Goo
                    return GH_ParamType.Param_Point;
                case "Rectangle": //RhinoCommon
                case "GH_Rectangle": //GH_Goo
                    return GH_ParamType.Param_Rectangle;
                case "ScriptVariable": //RhinoCommon
                case "GH_ScriptVariable": //GH_Goo
                    return GH_ParamType.Param_ScriptVariable;
                case "string": // system
                case "GH_String": //GH_Goo
                    return GH_ParamType.Param_String;
                case "StructurePath": //RhinoCommon
                case "GH_StructurePath": //GH_Goo
                    return GH_ParamType.Param_StructurePath;
                case "Surface": //RhinoCommon
                case "GH_Surface": //GH_Goo
                    return GH_ParamType.Param_Surface;
                case "Time": //RhinoCommon
                case "GH_Time": //GH_Goo
                    return GH_ParamType.Param_Time;
                case "Transform": //RhinoCommon
                case "GH_Transform": //GH_Goo
                    return GH_ParamType.Param_Transform;
                case "Vector3d": //RhinoCommon
                case "GH_Vector": //GH_Goo
                    return GH_ParamType.Param_Vector;
            }
        }
        static GH_ParamAccess GetAccess(GH_ParamSyntaxNodeInfo info)
        {
            switch (info.MethodName)
            {
                default:
                case "GetTree":
                case "SetTree":
                    return GH_ParamAccess.tree;
                case "GetList":
                case "SetList":
                    return GH_ParamAccess.list;
                case "GetItem":
                case "SetItem":
                    return GH_ParamAccess.item;
            }
        }


        public static IGH_Param GetParam(ParamInfo info)
        {
            switch (info.ParamType)
            {
                default:
                case GH_ParamType.Param_GenericObject:
                    return new Param_GenericObject();
                case GH_ParamType.Param_Arc:
                    return new Param_Arc();
                case GH_ParamType.Param_Boolean:
                    return new Param_Boolean();
                case GH_ParamType.Param_Box:
                    return new Param_Box();
                case GH_ParamType.Param_Brep:
                    return new Param_Brep();
                case GH_ParamType.Param_Circle:
                    return new Param_Circle();
                case GH_ParamType.Param_Colour:
                    return new Param_Colour();
                case GH_ParamType.Param_Complex:
                    return new Param_Complex();
                case GH_ParamType.Param_Culture:
                    return new Param_Culture();
                case GH_ParamType.Param_Curve:
                    return new Param_Curve();
                case GH_ParamType.Param_Field:
                    return new Param_Field();
                case GH_ParamType.Param_Geometry:
                    return new Param_Geometry();
                case GH_ParamType.Param_Group:
                    return new Param_Group();
                case GH_ParamType.Param_Integer:
                    return new Param_Integer();
                case GH_ParamType.Param_Interval:
                    return new Param_Interval();
                case GH_ParamType.Param_Interval2D:
                    return new Param_Interval2D();
                case GH_ParamType.Param_Line:
                    return new Param_Line();
                case GH_ParamType.Param_Matrix:
                    return new Param_Matrix();
                case GH_ParamType.Param_Mesh:
                    return new Param_Mesh();
                case GH_ParamType.Param_MeshFace:
                    return new Param_MeshFace();
                case GH_ParamType.Param_Number:
                    return new Param_Number();
                case GH_ParamType.Param_Plane:
                    return new Param_Plane();
                case GH_ParamType.Param_Point:
                    return new Param_Point();
                case GH_ParamType.Param_Rectangle:
                    return new Param_Rectangle();
                case GH_ParamType.Param_ScriptVariable:
                    return new Param_ScriptVariable();
                case GH_ParamType.Param_String:
                    return new Param_String();
                case GH_ParamType.Param_StructurePath:
                    return new Param_StructurePath();
                case GH_ParamType.Param_Surface:
                    return new Param_Surface();
                case GH_ParamType.Param_Time:
                    return new Param_Time();
                case GH_ParamType.Param_Transform:
                    return new Param_Transform();
                case GH_ParamType.Param_Vector:
                    return new Param_Vector();
            }
        }

    }
}
